package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.common.security.utils.SecurityUtils;
import com.share.device.domain.PowerBank;
import com.share.device.service.IPowerBankService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/10/11 下午2:15
 */
@Tag(name = "充电宝接口管理")
@RestController
@RequestMapping("/powerBank")
@RequiredArgsConstructor
public class PowerBankController extends BaseController {

    private final IPowerBankService powerBankService;

    /**
     * 获取充电宝详情
     * @param id
     * @return
     */

    @Operation(summary = "获取充电宝详情")
    @RequiresPermissions("device:powerBank:query")
    @Log(title = "充电宝")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id){
        return success(powerBankService.getById(id));
    }

    /**
     * 添加充电宝
     * @param powerBank
     * @return
     */
    @Operation(summary = "添加充电宝")
    @RequiresPermissions("device:powerBank:add")
    @Log(title = "充电宝",businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@RequestBody PowerBank powerBank){
        powerBank.setCreateBy(SecurityUtils.getUsername());
        powerBank.setCreateTime(new Date());
        powerBank.setUpdateTime(new Date());
        return toAjax(powerBankService.savePowerBank(powerBank));
    }

    /**
     * 修改充电宝信息
     * @param powerBank
     * @return
     */
    @Operation(summary = "修改充电宝信息")
    @RequiresPermissions("device:powerBank:edit")
    @Log(title = "充电宝",businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult update(@RequestBody PowerBank powerBank){
        powerBank.setUpdateBy(SecurityUtils.getUsername());
        powerBank.setUpdateTime(new Date());
        return toAjax(powerBankService.updatePowerBank(powerBank));
    }

    /**
     * 删除充电宝
     * @param ids
     * @return
     */
    @Operation(summary = "删除充电宝")
    @RequiresPermissions("device:powerBank:remove")
    @Log(title = "充电宝",businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids){
        return toAjax(powerBankService.removeBatchByIds(ids));
    }



    /**
     * 查询充电包列表
     * @param powerBank
     * @return
     */
    @Operation(summary = "查询充电宝列表")
    @RequiresPermissions("device:powerBank:list")
    @Log(title = "充电宝")
    @GetMapping("/list")
    public TableDataInfo list(PowerBank powerBank){
        startPage();
        return getDataTable(powerBankService.selectPowerBankList(powerBank));
    }

    /**
     * 搜索未使用的充电宝
     * @param keyword
     * @return
     */
    @Operation(summary = "搜索未使用的充电宝")
    @GetMapping("/searchNoUseList/{keyword}")
    public AjaxResult searchNoUseList(@PathVariable String keyword){
        return success(powerBankService.searchNoUseList(keyword));
    }

    /**
     * 设置充电宝数据
     * @param params
     * @return
     */
    @Operation(summary = "设置充电宝数据")
    @PostMapping("/setData")
    public AjaxResult setData(@RequestBody Map<String,Object> params){
        return success(powerBankService.setData(params));
    }


}
